package com.daniel.file;

import java.io.File;
 
public class FileCounter {
    public static void main(String[] args) {
        File folder = new File("D:\\Note\\ZoeyNote"); // 替换为你的目录路径
        String extension = ".md"; // 指定文件后缀名
 
        int fileCount = countFilesWithExtension(folder, extension);
        System.out.println("Number of " + extension + " files: " + fileCount);
    }
 
    public static int countFilesWithExtension(File folder, String extension) {
        int count = 0;
        File[] files = folder.listFiles();
        if (files != null) {
            for (File file : files) {
                if (file.isFile() && file.getName().toLowerCase().endsWith(extension.toLowerCase())) {
                    count++;
                    System.out.println(file.getName());
                } else if (file.isDirectory()) {
                    count += countFilesWithExtension(file, extension);
                }
            }
        }
        return count;
    }
}